package com.ruoyi.manager.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manager.domain.ArvinPassword;
import com.ruoyi.manager.service.IArvinPasswordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账号管理Controller
 * 
 * @author ruoyi
 * @date 2020-09-03
 */
@RestController
@RequestMapping("/password/password")
public class ArvinPasswordController extends BaseController
{
    @Autowired
    private IArvinPasswordService arvinPasswordService;

    /**
     * 查询账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('password:password:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArvinPassword arvinPassword)
    {
        startPage();
        List<ArvinPassword> list = arvinPasswordService.selectArvinPasswordList(arvinPassword);
        return getDataTable(list);
    }

    /**
     * 导出账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('password:password:export')")
    @Log(title = "账号管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArvinPassword arvinPassword)
    {
        List<ArvinPassword> list = arvinPasswordService.selectArvinPasswordList(arvinPassword);
        ExcelUtil<ArvinPassword> util = new ExcelUtil<ArvinPassword>(ArvinPassword.class);
        return util.exportExcel(list, "password");
    }

    /**
     * 获取账号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('password:password:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(arvinPasswordService.selectArvinPasswordById(id));
    }

    /**
     * 新增账号管理
     */
    @PreAuthorize("@ss.hasPermi('password:password:add')")
    @Log(title = "账号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArvinPassword arvinPassword)
    {
        arvinPassword.setUserId(getUserId());
        return toAjax(arvinPasswordService.insertArvinPassword(arvinPassword));
    }

    /**
     * 修改账号管理
     */
    @PreAuthorize("@ss.hasPermi('password:password:edit')")
    @Log(title = "账号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArvinPassword arvinPassword)
    {
        return toAjax(arvinPasswordService.updateArvinPassword(arvinPassword));
    }

    /**
     * 删除账号管理
     */
    @PreAuthorize("@ss.hasPermi('password:password:remove')")
    @Log(title = "账号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arvinPasswordService.deleteArvinPasswordByIds(ids));
    }
}
